﻿using Stockholm.SOA.Kaskelot.WCF.Core;
using Stockholm.SOA.Kaskelot.WCF.FaultContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.Text;

namespace Stockholm.SOA.Kaskelot.WCF.ServiceImplementation.ErrorHandling
{
    public class ErrorHandler : IErrorHandler
    {
        public bool HandleError(Exception error)
        {
            Logger.LogError(error.ToString());
            return true;
        }

        public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault)
        {
            FaultException<ErrorInformation> faultException = new FaultException<ErrorInformation>(new ErrorInformation { ServiceError = error.Message }, new FaultReason("Unhandled exception"));
            MessageFault messageFault = faultException.CreateMessageFault();
            fault = Message.CreateMessage(
             version, messageFault, faultException.Action);
        }
    }
}
